﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FishServe.Core.Services.UpdaterService
{
	internal class ReleaseManifestUtility
	{
		private ReleaseManifest mReleaseManifest;

		internal ReleaseManifestUtility(ReleaseManifest pReleaseManifest)
		{
			mReleaseManifest = pReleaseManifest;
		}

		/// <summary>
		/// Looks throught the ReleaseManifest object and return a list of fileHashTo Check.
		/// </summary>
		/// <param name="baseDirectory"></param>
		public void RetrieveFileListForHashCheck(string baseDirectory)
		{
			Dictionary<string, ManifestModuleInfo> list = new Dictionary<string, ManifestModuleInfo>();

			foreach (var item in mReleaseManifest.ModuleManifests)
			{
				ManifestModuleInfo info = item.Module;
				AddModuleManifest(list, info);

				foreach (var registeredType in item.RegisteredTypes)
				{
					AddModuleManifest(list, registeredType.FromTypeInfo.Module);
					AddModuleManifest(list, registeredType.ToTypeInfo.Module);
				}
				

				//item.DependentModules.ForEach( p=> );
			}
		}

		private void AddModuleManifest(Dictionary<string, ManifestModuleInfo> list, ManifestModuleInfo info)
		{
			if (!list.ContainsKey(info.FileHash))
			{
				list.Add(info.FileHash, info);
			}
		}
	}
}
